package com.fldx.baseboot.web.demo.service.impl;

import com.fldx.baseboot.web.demo.dao.DemoEnDao;
import com.fldx.baseboot.web.demo.service.DemoService;
import com.fldx.baseboot.web.domain.DemoEn;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import jakarta.annotation.Resource;
import java.util.Arrays;
import java.util.List;
@Service
public class DemoServiceImpl implements DemoService {
    @Resource
    DemoEnDao demoEnDao;

    @Override
    public List<DemoEn> selectDemoEn(DemoEn demoEn) {
        return demoEnDao.getDemoEnList(demoEn);
    }
    @Override
    public DemoEn getInfo(Long id) {
        return demoEnDao.findById(id).orElseThrow(()->new IllegalArgumentException("信息不存在"));
    }
    @Override
    public DemoEn create(DemoEn demoEn) {
        return demoEnDao.save(demoEn);
    }
    @Override
    public DemoEn update(DemoEn demoEn) {
        Assert.notNull(demoEn.getId(), "修改对象ID不能为空");
        DemoEn demoEnOld =  getInfo(demoEn.getId());
        Assert.notNull(demoEnOld, "用户不存在");
        return demoEnDao.save(demoEn);
    }
    @Override
    public void delete(Long id) {
        Assert.notNull(id, "ID不能为空");
        demoEnDao.deleteById(id);
    }

    @Override
    public void deleteBatch(Long[] ids) {
        List<Long> idList= Arrays.asList(ids);
        demoEnDao.deleteAllByIdInBatch(idList);
    }
}
